package com.itheima.dao;

import com.itheima.po.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookDao {

//      `id` int(11) NOT NULL AUTO_INCREMENT,
//  `TYPE` varchar(100) DEFAULT NULL,
//  `NAME` varchar(100) DEFAULT NULL,
//  `status` varchar(10) DEFAULT NULL,
//  `description` varchar(100) DEFAULT NULL,
//  PRIMARY KEY (`id`)
//) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8
//    插入语句
    @Insert("insert into tbl_book values(null, #{type},#{name},#{status},#{description})")
    int insert(Book book);
//update tbl_book set type = 'new', name = 'new', status = 'new', des
//                          -> cription = 'new' where id = 7
//    写dao层的时候，最好现在数据库中把sql写好，然后粘贴复制到代码中，然后在把需要修改的值进行替换成mybatis的占位符
    @Update("update tbl_book set type = #{type}, name = #{name}, status = #{status}, description = #{description}" +
            " where id = #{id}")
    int update(Book book);

    @Update("update tbl_book set status = #{status}" +
            " where id = #{id}")
    int updateStatusById(@Param("status") String status, @Param("id") int id);

    @Select("select * from tbl_book where id = #{id}")
    Book getById(int id);

    @Delete("delete from tbl_book where id = #{id}")
    int delete(int id);

    @Select("select * from tbl_book")
    List<Book> getAll();
}
